1. Field of the Invention
The invention relates to a method and buffer device for data stream transformation, more particularly to a method and buffer device for data stream transformation between line-based and block-based data streams.
2. Description of the Related Art
JPEG and MPEG are international standards in the fields of static and dynamic image compression, respectively. In the case of MPEG, as shown in FIG. 1, a data structure thereof consists of at least one sequence that includes a plurality of groups of pictures (abbreviated as GOP) . Each picture is further subdivided into a plurality of slices. Each slice is further subdivided into a plurality of macro blocks (abbreviated as MB) . Each macro block can be formed from four luminance blocks and a plurality of chrominance blocks. Finally, each block includes 8×8 bytes, which is defined as the smallest coding unit of the data structure in MPEG.
As shown in FIG. 2, to compress original image data in an MPEG-1 or MPEG-2 format, data stream transformation is first performed so as to convert an input data stream into a block-based output data stream, as indicated in step 201. Subsequently, in step 202, pixel data in each block are converted from time domain to frequency domain using discrete cosine transformation (DCT) so as to filter out high frequency components that are insensitive to the human eye. Then, in step 203, quantization is performed so as to quantize many converted DCT coefficients to zero. Next, in step 204, a zigzag scan operation is performed to re-arrange the quantized DCT coefficients in an increasing order of frequency. Thereafter, in step 205, differential pulse coded modulation (DPCM) is performed on DC coefficients, run length encoding (RLE) is performed on AC coefficients, and variable length coding (VLC) is finally performed on both coefficients so as to complete compression in the MPEG-1/MPEG-2 format. The JPEG compression operation is similar to the aforesaid process flow. In the same token, the aforesaid process flow is reversed when decompressing data.
Referring to FIG. 3, since both JPEG and MPEG use blocks as basic processing units, in order to transform a line-based input data stream into a block-based output data stream as required in step 201 of FIG. 2, a buffer memory 7 and a buffer controller 8 are typically used for processing.
When a data stream is written into the buffer memory 7 under the control of the buffer controller 8, the data stream is written in sequence from left to right and from top to bottom. However, since data are to be read in basic units of blocks, the buffer controller 8 will read data in a vertical direction (for example, read 8×8 bytes for output from top to bottom starting from the left topmost corner such that the content of the output data stream includes the first block). By virtue of this characteristic, data are not available for reading unless the buffer memory 7 is filled, and writing in the buffer memory 7 is possible only after data have been read therefrom.
Therefore, in general, the buffer memory 7 will be divided into two parts, where one part is used for input data, and the other part is used for output data. As shown in FIG. 3, when an upper part 71 is filled with data so that data can be outputted in units of blocks, a lower part 72 is available for a data writing operation. After data have been outputted from the upper part 71, the latter will be available for a subsequent data writing operation. Likewise, when the lower part 72 is filled with data, the data can be outputted therefrom.
Nevertheless, although the arrangement in FIG. 3 results in an increase in data input and output speeds, a large buffer memory 7 is required to ensure optimum performance.